package com.mostromas.ess.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mostromas.ess.entities.ProductSize;
import com.mostromas.ess.product.mapper.ProductSizeMapper;
import com.mostromas.ess.product.req.ProductSizeREQ;
import com.mostromas.ess.product.service.IProductSizeService;
import com.mostromas.ess.util.base.Result;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductSizeServiceImpl extends ServiceImpl<ProductSizeMapper, ProductSize> implements IProductSizeService {

    @Override
    public Result queryPage(ProductSizeREQ req) {
        QueryWrapper<ProductSize> wrapper = new QueryWrapper<>();

        if(StringUtils.isNotEmpty(req.getTypeId())){
            wrapper.eq("size_type_id",req.getTypeId());
        }

        wrapper.orderByAsc("size_type_id").orderByAsc("sort");

        return Result.ok(baseMapper.selectPage(req.getPage(),wrapper));
    }

    @Override
    public Result selectAll() {
        QueryWrapper<ProductSize> wrapper = new QueryWrapper<>();
        wrapper.orderByAsc("sort");
        List<ProductSize> data = baseMapper.selectList(wrapper);
        return Result.ok(data);
    }

    @Override
    public List<ProductSize> findSizesByProductId(String id) {
        List<ProductSize> sizeList = baseMapper.selectByProductId(id);
        return sizeList;
    }

}
